/**
 * Created by yangfan on 2016/12/28.
 */
/**
 * Created by Administrator on 2016/8/11.
 */
define(["require",'config/appregister',"business/workSkill/services/httpServices"],function(require,app,httpServices){
    app.controller('searchSkillCtrl',function($scope,$state){
        $scope.$parent.isDetailPage = false;
        $scope.$parent.isMainpage = true;
        /*一级分类*/
        $scope.goto1 = function(ctrl){
            $state.go(ctrl,{},{reload:true})
        }
        $scope.goto = function(item,Id,ctrl){
            $state.go(ctrl,{postbarId:Id})
        }
        $scope.goTo = function(item){
            $state.go("eng.workDetailsCtrl",{skillId:item.skillId})
        }
        $scope.linkfile=function(id){
            $state.go("eng.techdetail",{fileId:id})
        }
        function oneClass(){
            var req ={
                type:"GET",
                uri:"getTopCategory",
                data:{}
            };
            httpServices.oneClass(req).success(function(response){
                $scope.$apply(function(){
                    $scope.worktab=response.data
                })
            });
        }

        $scope.listParams = {
            currentTcId: "",
            download: false,
            time: false,
            pageNo: 1,
            pageSize:10,
            all: false,
            typeId: "",
            scId: "",
            dcId: "",
            keyWord:"",
            //dcName scName 用于加入缓存 在详情中显示面包树导航
            dcName:"",
            scName:""
        };
       

        if(sessionStorage.worlListId){
            oneClass();
            $scope.current=sessionStorage.worlListId;
            var req ={
                type:"GET",
                uri:"",
                data:{
                    tcId:sessionStorage.worlListId,
                    visitCount:"false",
                    publishTime:"false",
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.pageSize,
                    all:"false",
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    $scope.skillFileVoList = response.data.list.skillFileVoList;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    getListModel();
                })
            });
        }else{
            $scope.current = false;
            oneClass();
           
        if(sessionStorage.hasOwnProperty("searchKeyWord")){
            $scope.listParams.keyWord = sessionStorage.searchKeyWord ;
            var req ={
                type:"GET",
                uri:"",
                data:{
                    keyWord:$scope.listParams.keyWord,
                    all:"false",
                    pageNo:$scope.listParams.pageNo,
                    visitCount:"false",
                    publishTime:"false",
                    pageSize:$scope.listParams.pageSize,
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    var data = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    var order = "startTime";//默认开始时间显示
                    $scope.col = order;
                    $scope.desc = 0;
                  
                })
            });
        }else{
        	 getConList();
        }
        /*分页效果*/
      
        }
        /*默认列表内容*/
        function getConList(){
            var req ={
                type:"GET",
                uri:"",
                data:{
                    all:"false",
                    pageNo:$scope.listParams.pageNo,
                    visitCount:"false",
                    publishTime:"false",
                    pageSize:$scope.listParams.pageSize,
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    var data = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    var order = "startTime";//默认开始时间显示
                    $scope.col = order;
                    $scope.desc = 0;
                    getListModel();
                })
            });
        }
  		$scope.list = [];
        function getListModel(){
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage:$scope.listParams.pageSize,
                //分页总数
                numberOfPages:Math.ceil($scope.totalItem/$scope.listParams.pageSize),
                // 实际分页长度
                pagesLength:5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function (currentPage) {
                    if(currentPage){
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getConList();

                }
            };
        }

        /*点击一级分类切换*/
        $scope.switchData =  function(item){
            getListModel();
            $scope.listParams.pageNo =1;
            var switchId = item.tcId;
            $scope.current =  item.tcId;
            var req ={
                type:"GET",
                uri:"",
                data:{
                    tcId:switchId,
                    visitCount:"false",
                    publishTime:"false",
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.pageSize,
                    all:"false",
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    $scope.skillFileVoList = response.data.list.skillFileVoList;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    getListModel();
                })
            });
        }
        //点击全部执行默认操作
        $scope.WorkAll = function(){
            sessionStorage.removeItem("worlListId")
            $scope.current=false;
            getConList();
        }
        /*下载排行*/
        function downlaodRank(){
            var req ={
                type:"GET",
                uri:"getDownLoadRank?count=8",
                data:{}
            };
            httpServices.getDownd(req).success(function(response){
                $scope.$apply(function(){
                    $scope.RankCon = response.data.list;
                })
            });
        }
        downlaodRank();


        /*点击每个跳转*/
        $scope.linkSwitch = function(item){
            $state.go("eng.workDetailsCtrl",{skillId:item.skillId})
        }


        /*排序*/

        $scope.isDisabled = false;
         $scope.peopecolor = false;
        $scope.DateColor = function(){
            $scope.isDisabled = !$scope.isDisabled;
            var req ={
                type:"GET",
                uri:"",
                data:{
                    all:"false",
                    pageNo:$scope.listParams.pageNo,
                    visitCount:$scope.peopecolor,
                    publishTime:$scope.isDisabled,
                    pageSize:$scope.pageSize,
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    var data = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    var order = "startTime";//默认开始时间显示
                    $scope.col = order;
                    $scope.desc = 0;
                    getListModel();
                })
            });
        };
        $scope.peopecolor = false;
        $scope.peopleColor=function(){
            $scope.peopecolor = !$scope.peopecolor;
            var req ={
                type:"GET",
                uri:"",
                data:{
                    all:"false",
                    pageNo:$scope.listParams.pageNo,
                   	visitCount:$scope.peopecolor,
                    publishTime:$scope.isDisabled,
                    pageSize:$scope.pageSize,
                    count:"6"
                }
            };
            httpServices.getCOnlist(req).success(function(response){
                $scope.$apply(function(){
                    $scope.ConList = response.data.list;
                    var data = response.data.list;
                    $scope.totalItem = response.data.Pagination.totalCount;
                    var order = "startTime";//默认开始时间显示
                    $scope.col = order;
                    $scope.desc = 0;
                    getListModel();
                })
            });
        };
        /*字体八个颜色*/
        $scope.content = [
            {color:"#fe0000"},
            {color:"#fea100"},
            {color:"#f7f036"},
            {color:"#71cf0d"},
            {color:"#7edad9"},
            {color:"#83a6ef"},
            {color:"#f736da"},
            {color:"#fca5a5"}
        ]
        /*边框9个颜色*/
        $scope.border=[
            {
                border:"1px solid #35b558",
                color:"#35b558"
            },
            {
                border:"1px solid #cccccc",
                color:"#cccccc"
            },
            {
                border:"1px solid #ec251f",
                color:"#ec251f"
            },
            {
                border:"1px solid #35b558",
                color:"#35b558"
            },
            {
                border:"1px solid #cccccc",
                color:"#cccccc"
            },
            {
                border:"1px solid #ec251f",
                color:"#ec251f"
            },
            {
                border:"1px solid #35b558",
                color:"#35b558"
            },
            {
                border:"1px solid #cccccc",
                color:"#cccccc"
            },
            {
                border:"1px solid #ec251f",
                color:"#ec251f"
            }

        ]
    })
});


